import { ConfigProvider } from './../../config/config.provider';
import { Injectable } from '@nestjs/common';
import * as Redis from 'ioredis';

@Injectable()
export class RedisService {
  private redis: Redis;
  constructor() {
    this.redis = new Redis(ConfigProvider.getConfig('redis'));
  }

  set(key: string, value: string, expire: number = 60 * 60 * 24) {
    this.redis.set(key, value, 'EX', expire);
  }

  get(key: string) {
    return this.redis.get(key);
  }

  del(key: string) {
    this.redis.del(key);
  }
}
